/*
 * Copyright (C) 2011 TopCoder Inc., All Rights Reserved.
 */
package gov.nasa.pds.commandline;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

import gov.nasa.pds.processors.DataSetProcessor;
import gov.nasa.pds.services.DataSetProcessingException;

/**
 * <p>
 * The <code>DataSetProcessingCommandLine</code> class implements a command line utility for data sets
 * processing. The sole and required utility's parameter is the filename of the Spring configuration file.
 * </p>
 *
 * <strong>Thread Safety:</strong> This class is immutable and thread safe.
 *
 * @author KennyAlive
 * @version 1.0
 */
public class DataSetProcessingCommandLine {
    /**
     * Do not allow to create instances of command line utility class.
     */
    private DataSetProcessingCommandLine() {
        // Empty
    }

    /**
     * DataDictionaryCommandLine utility entry point. The sole and required command line argument is the
     * filename of the Spring configuration file.
     *
     * @param args command line arguments
     *
     * @throws BeansException
     *                  in case of loading/parsing errors of configuration file or if the bean could not be found
     * @throws DataSetProcessingException
     *                   if there is an error executing the engine
     */
    public static void main(String[] args) throws DataSetProcessingException {
        if (args.length < 1) {
            System.out.println("Usage: DataSetProcessingCommandLine <configuration_xml_filename>");
            return;
        }

        String configurationFilePath = args[0];
        Resource configurationResource = new FileSystemResource(configurationFilePath);

        BeanFactory factory = new XmlBeanFactory(configurationResource);
        DataSetProcessor dataSetProcessor = (DataSetProcessor)factory.getBean("dataSetProcessor");

        dataSetProcessor.processDataSet();
    }
}
